package com.cgly.medical.Util;

import com.cgly.medical.domain.Account;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @program: CGLY
 * @description:
 * @author: chen di
 * @create: 2022-08-22 11:26
 */


@RunWith(SpringJUnit4ClassRunner.class) //SpringJUnit4ClassRunner需要使用 JUnit 4.12 或更高版本
@SpringBootTest
public class redis {

    //自动注入redisTemplate
    @Autowired
    private RedisTemplate redisTemplate;
    @Test
    public void contextLoads() {
        //获取redis数据库连接对象
        RedisConnectionFactory connectionFactory = redisTemplate.getConnectionFactory();
        RedisConnection connection = connectionFactory.getConnection();

//        // 往Redis服务端中设置一个String类型的key，值为zhangsan
//        redisTemplate.opsForValue().set("name","zhangsan");
//        // 获取并打印这个key的值
//        System.out.println(redisTemplate.opsForValue().get("name"));
        redisTemplate.opsForValue().set("name","张三");				//往value中添加中文
        System.out.println(redisTemplate.opsForValue().get("name"));
    }

    @Test
    public void test1(){
        Account account = new Account();
        account.setId((long)666);
        account.setUname("chendi");
        account.setRealname("陈迪");
        redisTemplate.opsForValue().set("chendi",account);
    }

}